<?php


class ToIndex {
	
	private $content;
	
	public function __construct(){
		
		$q = "SELECT * FROM tb_gallery ORDER BY weight desc LIMIT 4 OFFSET 0";
		$r = mysql_query($q);
		
		while ($data = mysql_fetch_assoc($r)) {
			$arr[] = $data;
		}
		
		$count = sizeof($arr);
		$tpl_row = file_get_contents(dirname(__FILE__) . '/tpl/to_index_row.htm');
		
		$row = '';
		
		for($i = 0; $i < $count; $i++){
			$t = strtr($tpl_row,
				array(
				'{IMG}' => $arr[$i]['crop_img'],
				'{ID}' => $arr[$i]['id'],
				'{NAME}' => $arr[$i]['name']
					)
				);
			$row .= $t;
				
		}
		
		$this->content = strtr(file_get_contents(dirname(__FILE__) . '/tpl/to_index.htm'),
			array(
			'{ROWS}' => $row,
				)
			);
		
	}
	
	public function out(){
		
		return $this->content;
	}
}

?>